<template>
  <div>
    <!-- 主体部分 -->
    <section class="main">
      <input
        id="toggle-all"
        class="toggle-all"
        type="checkbox"
        @click="changeBtn"
      />
      <label for="toggle-all">Mark all as complete</label>
      <ul class="todo-list">
        <!-- 当任务已完成，可以给 li 加上 completed 类，会让元素加上删除线 -->
        <!-- <li class="completed">
          <div class="view">
            <input class="toggle" type="checkbox" checked />
            <label>读万卷书</label>
            <button class="destroy"></button>
          </div>
        </li> -->
        <li
          :class="{ completed: item.flag }"
          v-for="item in todolist"
          :key="item.id"
        >
          <div class="view">
            <input
              class="toggle"
              type="checkbox"
              v-model="item.flag"
              @change="changeFlag(item.id, $event)"
            />
            <label>{{ item.value }}</label>
            <button class="destroy" @click="del(item.id)"></button>
          </div>
        </li>
      </ul>
    </section>
  </div>
</template>

<script>
export default {
  name: 'todoMain',
  components: {},
  props: {
    todolist: {
      type: Array,
      required: false,
    },
  },
  data() {
    return {}
  },
  computed: {
    // selectAll: {
    //   get() {
    //     return this.todolist.every((item) => item.flag)
    //   },
    //   set(value) {
    //     this.todolist.forEach((item) => {
    //       item.flag = value
    //     })
    //   },
    // },
  },
  watch: {},
  created() {},
  methods: {
    del(id) {
      this.$emit('dellist', id)
    },
    changeFlag(id, e) {
      this.$emit('changeFlag', id, e.target.checked)
    },
    changeBtn() {
      this.$emit('changeBtn', true)
    },
  },
}
</script>

<style scoped></style>
